package demo3;

import javax.jws.soap.SOAPBinding;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-05-20
 * Time:21:50
 */
abstract class Animal{
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public abstract void eat();
}

interface IFlying {//提供一个飞的接口
    void fly();
}
interface IRunning {//提供一个跑的接口
    void run();
}
interface ISwimming {//提供一个游泳的接口
    void swim();
}

//叫 跑 游泳
class Duck extends Animal implements IRunning,IFlying,ISwimming{

    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(name+"正在吃鸭粮");
    }

    @Override
    public void fly() {
        System.out.println(name+"正在飞");
    }

    @Override
    public void run() {
        System.out.println(name+"正在跑");
    }

    @Override
    public void swim() {
        System.out.println(name+"正在游泳");
    }
}
class Dog extends Animal implements IRunning{
    public Dog(String name,int age){
        super(name,age);
    }
    @Override
    public void eat() {
        System.out.println(name+"正在吃狗粮");
    }

    @Override
    public void run() {
        System.out.println(name+"正在四条腿跑");
    }
}
//叫 跑 飞
//一定是先继承再实现
class Bird extends Animal implements IRunning,IFlying{
    public Bird(String name,int age){
        super(name,age);
    }
    @Override
    public void eat() {
        System.out.println(name+"正在吃鸟粮");
    }

    @Override
    public void run() {
        System.out.println(name+"正在用两条腿跑");
    }

    @Override
    public void fly() {
        System.out.println(name+"正在用翅膀飞");
    }
}
class Robot implements IFlying{

    @Override
    public void fly() {
        System.out.println("机器人正在飞");
    }
}

public class Test {

    public static void walk(IRunning iRunning){
        iRunning.run();
    }
    public static void fly(IFlying iFlying){
        iFlying.fly();
    }

    public static void main(String[] args) {
        //Dog没有实现FLY:fly(new Dog("狗子",1));
        fly(new Bird("鹦鹉",1));//这两个类都实现了ifly接口
        fly(new Duck("唐老鸭",1));

        fly(new Robot());
    }

    public static void main2(String[] args) {
        walk(new Dog("狗子",1));//这三个类都实现了running接口
        walk(new Bird("鹦鹉",1));
        walk(new Duck("唐老鸭",1));
    }

    public static void func1(Animal animal){
        animal.eat();
    }

    public static void main1(String[] args) {
        func1(new Dog("狗子",1));
        func1(new Bird("鹦鹉",1));
        func1(new Duck("唐老鸭",1));
    }
}
